package crmdna.common;

import crmdna.common.APIResponse.Status;

@SuppressWarnings("serial")
public class APIException extends RuntimeException {
	public Status statusCode;
	public String userFriendlyMessage;
	public Object object;
	
	public APIException() {		
	}
	
	public APIException status(Status status) {
		this.statusCode = status;
		return this;
	}
	
	public APIException message(String message) {
		this.userFriendlyMessage = message;
		return this;
	}
	
	public APIException object(Object object) {
		this.object = object;
		return this;
	}

	public APIException(Status statusCode, String userFriendlyMessage) {
		this.statusCode = statusCode;
		this.userFriendlyMessage = userFriendlyMessage;
	}

	public APIResponse toAPIResponse() {
		APIResponse resp = new APIResponse();
		
		resp.statusCode = statusCode;
		resp.userFriendlyMessage = userFriendlyMessage;
		resp.object = object;
		resp.stackTraceElements = getStackTrace();

		return resp;
	}
}
